package com.penglecode.netty.codec.protostuff;

import org.jboss.netty.buffer.ChannelBuffers;
import org.jboss.netty.channel.Channel;
import org.jboss.netty.channel.ChannelHandlerContext;
import org.jboss.netty.handler.codec.oneone.OneToOneEncoder;

import com.penglecode.protostuff.runtime.ObjectSerializer;

public class ProtostuffObjectEncoder extends OneToOneEncoder {

	private ObjectSerializer serializer;
	
	public ProtostuffObjectEncoder(ObjectSerializer serializer) {
		super();
		this.serializer = serializer;
	}

	protected Object encode(ChannelHandlerContext ctx, Channel channel,
			Object msg) throws Exception {
		return ChannelBuffers.wrappedBuffer(serializer.serialize(msg));
	}

}
